package com.huadao.cart_ccs.common.deviceController;

import com.huadao.cart_ccs.common.ParamsPreferences;

/**
 * 电子秤
 */
public class ElectronicScaleController {

    private double weight;//重量,下位机返回的值
    private double adjustWeight;//校准后的重量，根据a,b值校准后的值
    private byte[] ad;//AD值
//    private double weightChange;//重量的变化
    //校准参数
    private static double a;
    private static double b;
    private static final ElectronicScaleController ourInstance = new ElectronicScaleController();

    public static ElectronicScaleController getInstance() {
        return ourInstance;
    }

    private ElectronicScaleController() {
        a=ParamsPreferences.getInstance().getWeightAdjustA();
        b=ParamsPreferences.getInstance().getWeightAdjustB();
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
//        weightChange=weight-this.weight;
        this.weight = weight;
        adjustWeight=calculatedWeight(weight);
    }

    public byte[] getAd() {
        return ad;
    }

    public void setAd(byte[] ad) {
        this.ad = ad;
    }

//    public double getWeightChange() {
//        return weightChange;
//    }

    public void adjust(double a, double b) {
        this.a=a;
        this.b=b;
    }

    public static double calculatedWeight(double weight) {
        return a*weight+b;
    }
}
